#include "../include/InetAddress.h"
#include <string.h>
#include <arpa/inet.h>

namespace myNameSpace {
InetAddress::InetAddress(unsigned short port, const string &ip) {
    memset(&_addr, 0, sizeof(_addr));
    _addr.sin_family = AF_INET;
    _addr.sin_port = htons(port);
    _addr.sin_addr.s_addr = inet_addr(ip.c_str());
}

InetAddress::InetAddress(struct sockaddr_in &addr): _addr(addr) {}

struct sockaddr_in * InetAddress::getInetAddrPtr() {
    return &_addr;
}

string InetAddress::getIp() const {
    return inet_ntoa(_addr.sin_addr);
}

unsigned short InetAddress::getPort() const {
    return ntohs(_addr.sin_port);
}
} // end of namespace myNameSpace
